#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

int main()
{
	if(fork()==0){
		fork();
		fork();
		printf("subprocess pid %d\n", getpid());
		while(1) sleep(1);
		exit(0);
	}else{
		while(1){
			int i;
			int status;
			pid_t pid;
			printf("\n>");
			fflush(stdout);
			if(scanf("%d", &i)!=1) continue;
			printf("stop %d.\n", i);
			pid=(pid_t)i;
			if(fork()==0)
			{
				sleep(1);
				kill(pid, SIGSTOP);
				exit(0);
			}else{
				waitpid(pid, 0, 0);
				printf("status %d\n", status);
				printf("%d %d %d\n", WIFSTOPPED(status), WIFSIGNALED(status), WIFEXITED(status));
			}
		}
		exit(0);
	}
}
